<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h3 class="page-header">
				<span>投票项设置</span>
			</h3>
		</div>
		<!-- /.col-lg-12 -->
	</div>
	<!-- /.row -->

	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<button class="btn btn-success" onclick="show_detail_ori();" style="float: left">增加</button>
					<!--<form id="zjdailyCard" name="zjdailyCard" method="get" class="placedInline">-->
					<!--<button type="submit" formaction="{:U('User/Praise/download')}" formmethod="post" class="btn btn-sm btn-success dword-size">数据导出</button>-->
					<!--</form>-->
					<button class="btn btn-warning" onclick="download({$praiseid});" style="float: left;margin-left:5px">数据导出</button>

					<select class="form-control" style="margin-left:20%;width:200px;float: left" name="praise_id" id="praise_id">
						<?php
							foreach($praiseDatas as $praiseData){
								echo "<option value='" . $praiseData['id']. "' ";
								if($praiseData['id'] == $praiseid){
									echo selected;
								}
								echo ">".$praiseData['title']."</option>";
							}
						?>

					</select>
					<form class="input-group" action="/User/Praise/items" style="width: 300px;margin-left: 60%;">
						<input type="hidden" value="{$praiseid}" name="praise_id">
						<input type="text" class="form-control" name='itemName' placeholder="Search...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="submit">
								<i class="fa fa-search"></i>
							</button>
						</span>
					</form>

				</div>
				<!-- /.panel-heading -->
				<div class="panel-body">
					<div class="table-responsive">
						<table class="table table-bordered">
							<thead>
							<tr>
								<!--<th><input type="checkbox" data-action="checkboxAll"></th>-->
								<th width="5%">投票项</th>
								<th width="15%">名称</th>
								<th width="15%">简介</th>
								<th width="10%">结果</th>
								<th width="10%">浏览量</th>
								<th width="10%">图片</th>
								<th width="20%">操作</th>
							</tr>
							</thead>
							<tbody>
							<foreach name='datas' item='data' >
								<tr>
									<!--<td><input type="checkbox" data-action="checkboxOnce" name="praises[]" value="{$data['id']}" form="praiseOpera"></td>-->
									<td>{$data['grade']}</td>
									<td><span style="word-break:break-all;word-wrap:break-word">{$data['show_name']}</span></td>
									<td style="width: 100px;">{$data['contract']}</td>
									<td>{$data['votes']}</td>
									<td>{$data['pv']}</td>
									<td>
										<img class="thumbnail-sm" src="{$data['pic']}" alt="无" style="width:300px">
									</td>
									<td>
										<button type="button" onclick="edit_detail({$data['id']})" class="btn btn-success">编辑</button>
										<button type="button" onclick="item_delete({$data['id']})" class="btn btn-danger">删除</button>
									</td>
								</tr>
							</foreach>
							</tbody>
						</table>
					</div>
					<!-- /.table-responsive -->
				</div>
				<!-- /.panel-body -->
			</div>
			<!-- /.panel -->
		</div>
		<!-- /.col-lg-6 -->
	</div>
	<nav>
		<ul class="pagination">
			<php>
				$uri = $_SERVER['REQUEST_URI'];
				$str_p = strpos( $uri, 'page' );
				$str_q = false;
				if( $str_p != false ){
				//$str_q = strpos( $uri, "&", $str_p );
				$str_q = strlen($uri);
				}
				if( $str_p != false && $str_q != false ){
				$uri = substr_replace( $uri, "", $str_p, $str_q - $str_p );
				}
				$str_p = strrpos( $uri, "?" );
				if( $str_p == strlen($uri) - 1 ){
				$uri = substr_replace( $uri, "", $str_p, 1 );
				}
				$str_p = strrpos( $uri, "&" );
				if( $str_p == strlen($uri) - 1 ){
				$uri = substr_replace( $uri, "", $str_p, 1 );
				}
			</php>
			<if condition="$page['pre'] gt 0 ">
				<li>
					<a href="{:implode(array( $uri, '&', 'page', '=', $page['pre']) )}" aria-label="Previous">
						<span aria-hidden="true">&laquo;</span>
					</a>
				</li>
			</if>
			<for start="1" end=":intval( $page['count'] ) ">
				<li class="{$page['curren']==$i ? 'active':''}"><a href="{:implode(array( $uri, '&', 'page', '=', $i) )}">{$i}</a></li>
			</for>
			<if condition="$page['next'] lt ( $page['count'] )">
				<li>
					<a href="{:implode(array( $uri, '&', 'page', '=', $page['next']) )}" aria-label="Next">
						<span aria-hidden="true">&raquo;</span>
					</a>
				</li>
			</if>
		</ul>
	</nav>
	<!-- /.row -->
</div>
<!-- /#page-wrapper -->
<div class="modal fade netMsgModal" id="netMsgModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="change_detail()">&times;</button>
				<h4 class="modal-title">新建投票项</h4>
			</div>
			<div class="modal-body">
				<form class="form" action="{:U('User/Praise/item_edit')}" method="post" enctype="multipart/form-data">
					<input type="hidden" name="item_id" id="item_id" value="">
					<input type="hidden" name="page" value="<?php echo I('get.page', 1, '');?>">
					<input type="hidden" name="praise_id" value="<?php echo $praiseid;?>">
					<div class="form-group">
						<label>名称</label>
						<input class="form-control" name="show_name" id="show_name" value="">
					</div>
					<div class="form-group">
						<div>简介</div>
						<textarea id="contract" style="width:560px;height:300px;" name="contract"></textarea>
					</div>
					<div class="form-group" id="show_pic" style="display: none">
						<img width="100%" height="200px" src="" alt=" " id="add_pic" class="thumbnail preview" data-preview="uploadFile">
						<!-- <input type="hidden" name="picurl" value="{$praise['picurl']}" data-set="uploadFile"> -->
						<input name="picurl" type="file" data-action="uploadFile" style="margin-top: -10px;margin-bottom: 10px;" id="input_file">
					</div>
					<div class="form-group" id="show_pic1" style="display: none">
						<img src=""  class="thumbnail" width="100%" height="320px" data-preview="uploadFile1" id="change_pic">
						<input type="hidden" name="picurl1" id="change_pic_value" value="" data-set="uploadFile1">
						<input type="file" class="changePic" data-action="uploadFile1"  style="margin-top: -10px;margin-bottom: 10px;" id="input_file1">
					</div>
					<?php if($praise['type'] === 'video'){?>
					<div class="form-group">
						<label>视频地址</label>
						<input class="form-control" name="external_link" id="external_link" value="">
					</div>
					<?php }?>
					<div class="form-group">
						<label>是否跳转链接</label>
						<label class="radio-inline">
							<input type="radio" name="click" value="0"
							<?php if($praise['click'] == 0){
										echo 'checked';
										}?> onclick="set_redirect(0);"> 否
						</label>
						<label class="radio-inline">
							<input type="radio" name="click" value="1"
							<?php if($praise['click'] == 1){
										echo 'checked';
										}?> onclick="set_redirect(1);"> 是
						</label>
					</div>
					<div class="form-group" id="yuliu_div">
						<label>跳转链接</label>
						<input class="form-control" name="yuliu" id="yuliu" value="">
					</div>
					<div class="modal-footer">
						<button type="submit" class="btn btn-success">提交</button>
						<button type="button" class="btn btn-default" data-dismiss="modal" onclick="change_detail();">关闭</button>
					</div>
				</form>
			</div>

		</div><!-- /.modal-content -->
	</div>
</div>


<import type="js" file="common" basepath="/Public/js" />
<script type="text/javascript" src="/Public/js/common.cursor.js"></script>
<script type="text/javascript" src="/Public/js/common.upload.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.all.min.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/Public/js/common/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor = UE.getEditor('contract');
    var content = '';
    editor.addListener("ready", function () {
        editor.setContent(content);
    });
</script>
<script type="text/javascript">
	common.upload.img.init();
	$("#praise_id").change(function(){
		window.location = "/User/Praise/items?praise_id="+$("#praise_id").val();
	});
	common.cursor.preview.init({
		div: '.thumbnail-sm'
	});
	function show_detail(){
		$("#netMsgModal").modal( "show" );
	}
	function set_redirect(check){
	    if(check == 0){
            $("#yuliu_div").css("display", "none");
		}else{
            $("#yuliu_div").css("display", "block");
		}
	}
	var type = "{$praise['type']}";
	function edit_detail(id){
		$.ajax({
			url:"/User/Praise/item_get",
			data:{id:id},
			dataType:'json',
			success:function(res){
				$("#item_id").val(res['id']);
				$("#show_name").val(res['show_name']);
				editor.setContent(res['contract']);
				if(res['pic'] == "" || res['pic'] == undefined || res['pic'] == null) {
					$("#change_pic").attr("src","");
					$("#change_pic_value").val("");
					$("#input_file").val("");
					$("#input_file1").val("");
					$("#show_pic").css("display","block");
					$("#show_pic1").css("display","none");
				}else{
					$("#input_file").val("");
					$("#input_file1").val("");
					$("#change_pic").attr("src",res['pic']);
					$("#change_pic_value").val(res['pic']);
					$("#show_pic1").css("display","block");
					$("#show_pic").css("display","none");
				}
				if(type === 'video'){
					$("#external_link").val(res['external_link']);
				}
				$("#yuliu").val(res['yuliu']);
				if(res['click'] == 1){
				    $("input[name='click']").eq(1).attr("checked","checked");
                    $("input[name='click']").eq(1).click();
				    $("#yuliu_div").css("display", "block");
				}else{
                    $("input[name='click']").eq(0).attr("checked","checked");
                    $("input[name='click']").eq(0).click();
                    $("#yuliu_div").css("display", "none");
				}
				show_detail();
			}
		});
	}
	function change_detail(){
		$("#item_id").val("");
		$("#show_name").val("");
		editor.setContent('');
		$("#change_pic").attr("src","");
		$("#change_pic_value").val("");
		$("#input_file").val("");
		$("#input_file1").val("");
		$("#show_pic").css("display","block");
		$("#show_pic1").css("display","none");
        if(type === 'video'){
            $("#external_link").val("");
        }
        $("#yuliu").val("");
        $("#yuliu_div").css("display", "none");
        $("input[name='click']").eq(0).removeAttr("checked");
        $("input[name='click']").eq(1).removeAttr("checked");
	}
	function show_detail_ori(){
		change_detail();
		show_detail();
	}
	function item_delete(id){
		$.ajax({
			url:'/User/Praise/item_delete',
			data:{item_id:id},
			type:'get',
			success:function(res){
				window.location.reload();
			}
		});
	}
	function download(id){
        window.location = "/User/Praise/download?praise_id="+id;
	}
</script>

